<?php
$_setting_user = new user_controller();
        $width = 0;
        $color = '';
        $message = '';   
        $uservalue = '';
        $fnamevalue = '';
        $lnamevalue = '';
		$wnamevalue = '';
	    $urlvalue = '';
		$emailvalue = '';
    	$userInfo = "*";
    	$passInfo = "*";
    	$fnameInfo = "*";
    	$lnameInfo = "*";
    	$emailInfo = "*";
    	$male = "checked='checked'";
    	$female = "";
        $location = 'Argentina';
        $d = 1;
        $m = 1;
        $y = 1970;
    	$class_input_user = "inp-form";
    	$class_input_pass = "inp-form";
    	$class_input_fname = "inp-form";
    	$class_input_lname = "inp-form";
    	$class_input_email = "inp-form";
    	$class_input_wname = "inp-form";
    	$class_input_url = "inp-form";              
 if(isset($_POST['submit'])){
        if((!validateUser($_POST['txt_username'])) || (!validatePass($_POST['txt_password'])) || (!$_setting_user->checkEmail($_POST['txt_email'])) || (!$_setting_user->checkUser($_POST['txt_username']))
        || (!$_setting_user->isValidEmail($_POST['txt_email']))){
                         $width = 100;
                        $color = "red";
						$message = "Registry Account Failure !";
                         $uservalue = $_POST['txt_username'];
                		$emailvalue = $_POST['txt_email'];
                        if(isset($_POST['txt_firstname'])){
                        $fnamevalue = $_POST['txt_firstname'];
                        $lnamevalue = $_POST['txt_lastname'];
                		$wnamevalue = $_POST['txt_website'];
                	    $urlvalue = $_POST['txt_url'];
                        $location = $_POST['txt_location'];
                        if(!validateFirstname($_POST['txt_firstname'])){ $fnameInfo = "Firstname is not null !";$class_input_fname = "inp-form-error"; }
						if(!validateLastname($_POST['txt_lastname'])){ $lnameInfo = "Lastname is not null !";$class_input_lname = "inp-form-error"; }
                        }
                        if($_POST['txt_sex'] == 'male') $male = "checked='checked'"; else $female = "checked='checked'";
						$y = $_POST['y'];$m = $_POST['m'];$d = $_POST['d'];
						if(!validateUser($_POST['txt_username'])){ $userInfo = "Username must more than 4 letters !"; $class_input_user = "inp-form-error"; }
						if(!validatePass($_POST['txt_password'])){ $passInfo = "Password must more than 6 letters !"; $class_input_pass = "inp-form-error"; }
						if(!$_setting_user->isValidEmail($_POST['txt_email'])){ $emailInfo = "Type a valid e-mail please :P";$class_input_email = "inp-form-error"; }
                        elseif (!$_setting_user->checkEmail($_POST['txt_email'])){$emailInfo = "Email is ready exits !";$class_input_email = "inp-form-error";}
						if(!$_setting_user->checkUser($_POST['txt_username'])){$userInfo = "Username is ready exits !"; $class_input_user = "inp-form-error";}    
        }else{
                         $width = 100;
                        $color = "green";
						$birthday = $_POST['y'] . '-' . $_POST['m'] . '-' . $_POST['d'];
						$account = new users('', $_POST['txt_username'], $_POST['txt_password'], $_POST['txt_firstname'], $_POST['txt_lastname'], $_POST['txt_sex'], $_POST['txt_email'], $birthday, $_POST['txt_website'], $_POST['txt_url'],2, $_POST['txt_location']);
						if($_setting_user->addAcount($account))$message = "Registry Account Successfully !";
        }
    } 
?>

<div class="clear"></div>
    <div id="content-outer">
        <!-- start content -->
        <div class="center">
        <div id="content">
            <div id="page-heading"><h1>Registrator</h1></div>
            <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
                <tr>
                    <th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
                    <th class="topleft"></th>
                    <td id="tbl-border-top">&nbsp;</td>
                    <th class="topright"></th>
                    <th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
                </tr>
                <tr>
                    <td id="tbl-border-left"></td>
                    <td>
                        <!--  start content-table-inner -->
                        <div id="content-table-inner">
							<div id="message-<?php echo $color?>">
								<table border="0" width="<?php echo $width."%"?>" cellpadding="0" cellspacing="0">
									<tr>
										<td class="<?php echo $color?>-left"><?php echo $message?></td>
										<td class="<?php echo $color?>-right">
											<a class="close-<?php echo $color?>"><img src="images/table/icon_close_<?php echo $color?>.gif"   alt="Close" />											</a>
										</td>
										</tr>
								</table>
							</div>  
                            <form action="" method="POST">
                                <table border="0" width="100%" cellpadding="0" cellspacing="0">
                                    <tr valign="top">
                                        <td>
                                            <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                                <tr>
                                                    <th valign="top">Username :</th>
                                                    <td>
														<input id="txt_username" name="txt_username" type="text" class="<?php echo $class_input_user?>" value="<?php echo $uservalue?>" />
														<span id="userInfo" class="error"><?php echo $userInfo?></span>
													</td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Password :</th>
                                                    <td>
														<input id="txt_password" type="password" name="txt_password" class="<?php echo $class_input_pass?>" />
														<span id="passInfo" class="error"><?php echo $passInfo?></span>
													</td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Firstname :</th>
                                                    <td>
														<input id="txt_firstname" name="txt_firstname" type="text" class="<?php echo $class_input_fname?>" value="<?php echo $fnamevalue?>" />
														<span id="fnameInfo" class="error"><?php echo $fnameInfo?></span>	
													</td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Lastname :</th>
                                                    <td>
														<input id="txt_lastname" type="text" name="txt_lastname" class="<?php echo $class_input_lname?>" value="<?php echo $lnamevalue?>" />
														<span id="lnameInfo" class="error"><?php echo $lnameInfo?></span>
													</td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Sex :</th>
                                                    <td>
                                                        <input type="radio" name="txt_sex" value="male" <?php echo $male ?> />Male
                                                        <input type="radio" name="txt_sex" value="female" <?php echo $female ?>/>Female
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Email :</th>
                                                    <td>
														<input id="txt_email" type="text" name="txt_email" class="<?php echo $class_input_email?>" value="<?php echo $emailvalue?>"/>
														<span id="emailInfo" class="error"><?php echo $emailInfo?></span>
													</td>
                                                </tr>
                                                <tr id="location-box">
                                                    <th valign="top">Location :</th>
                                                    <td>
                                                        <select id="txt_location" name="txt_location" class="text" >
                                                        <?php
                                                            $mo = array("Argentina","Austria","Australia","Angola","Bolivia","Brazil","Canada","China","Chile","Colombia","Cuba","Denmark","England","Ecuador","Egypt","France","Germany","Haiti","Indonesia","Jamaica","Japan","Korea","Malaysia","Mexico","Paraguay","Peru","Singapore","Russia","Turkey","Thailand","Venezuela","Vietnam","Uruguay","USA");
															for($n=0;$n<count($mo);$n++)if($mo[$n] == $location) echo  "<option value='".$mo[$n]."' selected='selected'>".$mo[$n]."</option>";else echo "<option value='".$mo[$n]."'>".$mo[$n]."</option>";
                                                         ?>      
                                                        </select>
													</td>
                                                </tr>
                                                <tr id="birthday-box">
                                                    <th valign="top">Birthday :</th>
                                                    <td class="noheight">
                                                        <table border="0" cellpadding="0" cellspacing="0">
                                                            <tr  valign="top">
                                                                <td>
                                                                    <form id="chooseDateForm" action="#">
                                                                        <select id="d" name="d" class="styledselect-day">
																			<?php for($n=1;$n<32;$n++) if($n == $d) echo  "<option value='".$n."' selected='selected'>".$n."</option>"; else echo "<option value='".$n."'>".$n."</option>";?>
                                                                        </select>
                                                                </td>
                                                                <td>
                                                                    <select id="m" name="m" class="styledselect-month">
																		<?php 
																			$mo = array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
																			for($n=1;$n<=12;$n++)if($n == $m) echo  "<option value='".$n."' selected='selected'>".$mo[$n]."</option>";else echo "<option value='".$n."'>".$mo[$n]."</option>";
																		?>
                                                                    </select>
                                                                </td>
                                                                <td>
                                                                    <select  id="y" name="y"  class="styledselect-year">
																		<?php for($n=1970;$n<=1995;$n++)if($n == $y) echo  "<option value='".$n."' selected='selected'>".$n."</option>";else  echo "<option value='".$n."'>".$n."</option>";?>
                                                                    </select>
                                                                    </form>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Website Name :</th>
                                                    <td><input type="text" name="txt_website" class="<?php echo $class_input_wname?>" value="<?php echo $wnamevalue?>" /></td>
                                                    <td></td>
                                                </tr> 
                                                <tr>
                                                    <th valign="top">URL Site :</th>
                                                    <td><input name="txt_url" type="text" class="<?php echo $class_input_url?>" value="<?php echo $urlvalue?>" /></td>
                                                    <td></td>
                                                </tr>
                                                <tr>
                                                    <th>&nbsp;</th>
                                                    <td valign="top">
                                                        <input type="submit" name="submit" value="submit" class="form-submit" />
														<a onclick="location='index.php?action=cancel'" class="form-cancel">Cancel</a>
                                                        <input type="reset" value="" class="form-reset"  />
                                                    </td>
                                                    <td></td>
                                                </tr>
                                            </table>
                                            <!-- end id-form  -->
                                    <tr>
                                        <td><img src="images/shared/blank.gif" width="695" height="1" alt="blank" /></td>
                                    </tr>
                                </table>
                            </form>
                            <div class="clear"></div>
                        </div>
                        <!--  end content-table-inner  -->
                    </td>
                    <td id="tbl-border-right"></td>
                </tr>
                <tr>
                    <th class="sized bottomleft"></th>
                    <td id="tbl-border-bottom">&nbsp;</td>
                    <th class="sized bottomright"></th>
                </tr>
            </table>
            <div class="clear">&nbsp;</div>
        </div>
        </div>
        <!--  end content -->
        <div class="clear">&nbsp;</div>
    </div>
<script type="text/javascript" src="js/validuser.js"></script>